package com.freshcity.page.home
{
	import com.freshcity.common.FriendShowWin;
	import com.freshcity.component.BaseGameObject;
	import com.freshcity.component.container.Component;
	import com.freshcity.core.Dispatcher;
	import com.freshcity.core.GlobalVar;
	import com.freshcity.core.MainScene;
	import com.freshcity.core.OpCodes;
	import com.freshcity.lib.event.EventName;
	import com.freshcity.manager.CommunicatorManager;
	import com.freshcity.manager.MsgManager;
	import com.freshcity.manager.support.WindowLayer;
	import com.freshcity.page.common.OnlineIcon;
	import com.freshcity.page.friend.FriendHome;
	import com.freshcity.utils.BitmapUtil;
	import com.freshcity.utils.MessageUtil;
	import com.freshcity.utils.StringUtil;
	import com.greensock.TweenLite;
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.ImageLoader;
	import com.pblabs.PBE;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	public class FriendShow extends Component
	{
		public var asso:*;

		public var back:FriendShowWin;
		public var xpos:Number;
		public var ypos:Number;
		private var imageLoader:ImageLoader;
		private var onlineIcon:OnlineIcon;

		public function FriendShow(parent:DisplayObjectContainer,main:MainScene, xpos:Number=0, ypos:Number=0)
		{
			this.main = main;
			this._width = 110;
			this._height = 160;
			super(parent, xpos, ypos);
			this.buttonMode=true;
			this.addEventListener(MouseEvent.CLICK, onShowDetail,false,0,true);
			this.addEventListener(MouseEvent.MOUSE_OVER,onMouseOverHandler,false,0,true);
		}
		
		protected function onMouseOverHandler(event:MouseEvent):void
		{
			TweenLite.to(back.assoDesc,0.2,{alpha:1});
			this.addEventListener(MouseEvent.MOUSE_OUT,onMouseOutHandler);
		}
		
		protected function onMouseOutHandler(event:MouseEvent):void
		{
			this.removeEventListener(MouseEvent.MOUSE_OUT,onMouseOutHandler);
			TweenLite.to(back.assoDesc,0.2,{alpha:0});
		}
		
		override protected function addChildren():void
		{
			super.addChildren();
			back=new FriendShowWin();
			back.x=xpos;
			back.y=ypos;
			addChild(back);
			
			onlineIcon = new OnlineIcon(back);
		}

		override public function draw():void
		{
			super.draw();
			main.user.sex == 'female' ? back.userPic.gotoAndStop("male") : back.userPic.gotoAndStop("female");
			back.nikeName.text=asso.nikeName;
			BitmapUtil.showAvatarPic(asso,back.userPic);
			back.assoDesc["assoLabel"].text = MessageUtil.decodeAssoLevel(asso.level);
			back.assoDesc.alpha = 0;
			setStatus();
		}
		
		public function setStatus():void
		{
			onlineIcon.online = (asso.online != null);
		}

		protected function onShowDetail(event:MouseEvent):void
		{
			Dispatcher.addEventListener(EventName.UserReadDone,main.showUser);
			main.findUser(asso.id);
		}
		
		override public function destroy():void
		{
			if(this.hasEventListener(MouseEvent.CLICK)){
				this.removeEventListener(MouseEvent.CLICK, onShowDetail);
			}
			super.destroy();
		}

	}
}